package org.rqb.ui.panel;

import javax.swing.*;
import java.awt.*;
import java.util.Objects;

public class BackgroundPanel extends JPanel {

    private final Image bgImage;

    public BackgroundPanel(String classpathImage) {
        // 从类路径加载图片
        this.bgImage = new ImageIcon(
                Objects.requireNonNull(getClass().getResource(classpathImage),
                        "找不到背景图片：" + classpathImage)
        ).getImage();
    }

    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        if (bgImage != null) {
            g.drawImage(bgImage, 0, 0, getWidth(), getHeight(), this);
        }
    }
}
